


import 'package:bt_tool/basic/bt_color_tool.dart';
import 'package:bt_tool/basic/bt_common_define.dart';
import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/widget/bt_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/common/config/app_theme_color_config.dart';
import 'package:flutter_demo/tools/donext/page/do_next_main_page.dart';
import 'package:flutter_demo/tools/encode/encode_main_page.dart';
import 'package:flutter_demo/tools/encrypt/encrypt_main_page.dart';
import 'package:flutter_demo/tools/json/json_main_page.dart';
import 'package:flutter_demo/tools/tools_main_controller.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
import '../common/config/app_config.dart';
import 'copy/copy_past_main_page.dart';
import 'credit/credit_main_page.dart';

class ToolsMainPage extends BTStatefulWidget{

  const ToolsMainPage({super.key,super.routerConfig});

  @override
  State<StatefulWidget> createState() {
    return ToolsMainPageState();
  }

}

class ToolsMainPageState extends BTState<ToolsMainPage>{


  final ToolsMainController controller = ToolsMainController();

  @override
  BTController btCtrl(){
    return controller;
  }



  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints.expand(),
      child: Stack(
        children: [
          Positioned(
            top: 0,
            left: 0,
            bottom: 0,
            width: controller.leftContentWidth,
            child: Obx((){
              return ToolsMainLeftWidget(
                selectIndex: controller.selectIndex.value,
                clickCallback:(index){
                  controller.itemClick(index);
                },
                mainController: controller,
              );
            }),
          ),
          Positioned(
            top: 0,
            left: controller.leftContentWidth,
            bottom: 0,
            right: 0,
            child: Obx(()=>IndexedStack(
                sizing: StackFit.expand,
                index: controller.selectIndex.value,
                children: controller.listWidget)),
          ),
        ],
      ),
    );
  }



}

class ToolsMainLeftWidget extends BTStatelessWidget{
  
  final int selectIndex;
  final BTCommonIntCallback clickCallback;
  final ToolsMainController mainController;

  const ToolsMainLeftWidget({
    super.key,
    required this.selectIndex,
    required this.clickCallback,
    required this.mainController,
  });

  @override
  Widget build(BuildContext context) {

    List<Widget> listWidget = [
      const SizedBox(height: 12,),
      Image.asset(btPngPath("tools/tools_icon"),width: 35,height: 35,),
    ];

    int index = 0;
    for(var str in mainController.tabbarNameList){
      listWidget.add(const SizedBox(height: 12,));
      listWidget.add(createItemView(str, index));
      index++;
    }

    return Container(
      constraints: const BoxConstraints.expand(),
      decoration: BoxDecoration(
          color: BTColor.fromHex("#e2e2e2")
      ),
      child: Column(
        children: listWidget,
      ),
    );
  }

  Widget createItemView(String text,int index){
    return GestureDetector(
      onTap: (){
        clickCallback(index);
      },
      child: Container(
        margin: const EdgeInsets.only(left: 8,right: 8),
        alignment: Alignment.center,
        constraints: const BoxConstraints.expand(height: 35),
        decoration: BoxDecoration(
            color: index == selectIndex ? AppThemeColor.mainColor :BTColor.fromHex("#ebebeb"),
            borderRadius: const BorderRadius.all(Radius.circular(4))
        ),
        child: Text(text,style: TextStyle(color: index == selectIndex ? Colors.white : AppThemeColor.textColor),),
      ),
    );
  }
  
}

